var yaer = Number(prompt("请输入年份"));

var month = Number(prompt("请输入月份"));

//计算平年和闰年

function runNian(yaer) {
	if(yaer % 400 == 0 || (yaer % 4 == 0 && yaer % 100 != 0)) {
		return true;
	} else {
		return false;
	}
}

//	计算 1980到2019一共多少天

var days = 0;

for(var i = 1980; i < yaer; i++) {
	if(runNian(i)) {
		days += 366;
	} else {
		days += 365;
	}
}

//	1-4月一共多少天

for(k = 1; k < month; k++) {
	switch(k) {
		case 1:
			days += 31;
			break;
		case 2:
			if(runNian(yaer)) {
				days += 29;
			} else {
				days += 28;
			}
			break;
		case 3:
			days += 31;
			break;
		case 4:
			days += 30;
			break;
		case 5:
			days += 31;
			break;
		case 6:
			days += 30;
			break;
		case 7:
			days += 31;
			break;
		case 8:
			days += 31;
			break;
		case 9:
			days += 30;
			break;
		case 10:
			days += 31;
			break;
		case 11:
			days += 30;
			break;
		case 12:
			days += 31;
			break;
	}
}
days += 2;

var start = days % 7;

//	上个月有多少天

var shangyue = 0;
//var shangDay = month == 1?12:month-1;
switch(month-1) {
	case 0:
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		shangyue += 31;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		shangyue += 30;
		break;

	case 2:
		if(runNian(yaer)) {
			shangyue += 29;
		} else {
			shangyue += 28;
		}
}

// 计算本月有多少天

var benyue = 0;

switch(month) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		benyue += 31;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		benyue += 30;
		break;
	case 2:
		if(runNian(yaer)) {
			benyue += 29;
		} else {
			benyue += 28;
		}
}

var day= document.querySelector("#day")
for(var i=shangyue-start+1;i<=shangyue;i++){
	day.innerHTML+='<span class=h>'+i+'</span>'
}

//本月

	var today = new Date().getDate();
	
	for (i=1; i<=benyue; i++){
		if(i==today){
			day.innerHTML+="<span class=today>"+i+"<span>"
		}else{
			day.innerHTML+='<span>'+i+'</span>'
		}
	}


	var num = 42;
	
	var shangyue = num - benyue - start;
	
	for(var i = 1; i <= shangyue; i++){
		day.innerHTML+='<span class=h>'+i+'</span>'
	}

	document.querySelector("#nian").innerHTML = yaer;
	
	document.querySelector("#yue").innerHTML = month;